from rest_framework import serializers
from .models import Area

class AreaSerializer(serializers.ModelSerializer):
    """
     序列化器

     [{'id:1,'name':'xxxx'},{'id:1,'name':'xxxx'}{'id:1,'name':'xxxx'}]
     """

    class Meta:
        model = Area
        fields = ['id', 'name']


class SubAreaSerializer(serializers.ModelSerializer):
    # related_name='subs'
    # 因为我设置了 修改 关联模型 的名字
    # area_set = AreaSerializer(many=True,read_only=True)
    subs = AreaSerializer(many=True, read_only=True)

    class Meta:
        model = Area
        fields = ('id', 'name', 'subs')
